var express = require('express')
var mongooes = require('mongoose')
var nunjucks = require('nunjucks')
var router = require('./routes/index')
var bodyParser = require('body-parser');

mongooes.connect('mongodb://127.0.0.1:27017/qijie')
var db = mongooes.connection
db.on('error', console.error.bind(console, 'connection error:'))
db.once('open', function() {
  console.log('服务器链接成功')
});
var app = express()

app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({ extended: true }));

nunjucks.configure('views', {
  autoescape: true,
  express: app
});
nunjucks.configure('/views')


app.use(router)

app.listen('8081', function(err,data){
  if(err){
    console.log(err)
  }else{
    console.log(`SERVER START SUCCESS ON http://localhost:8081`)
  }
}) 
